package com.wsd.jing.controller.application;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.wsd.jing.annotation.ControllerLog;
import com.wsd.jing.entity.Test;
import com.wsd.jing.request.CommonRequest;
import com.wsd.jing.request.CommonResponse;
import com.wsd.jing.service.ITestService;
import com.wsd.jing.validator.group.InsertGroup;
import com.wsd.jing.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;

import org.springframework.web.bind.annotation.*;

/**
 * All rights Reserved, Designed By www.tom.com
 *
 * @author tom
 * @version 1.0.0
 * @projectName: jing
 * @packageName: com.wsd.jing.controller
 * @className: TestController
 * @description: Test前端控制器
 * @createDate 2024-07-04 03:57
 * @copyright 2024-07-04 03:57 www.tom.com Inc. All rights reserved.
 */
@Api(tags = "Test")
@Validated
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/rest/test")
public class TestController {

    private final ITestService testService;

    @ApiOperation(value = "新增")
    @PostMapping()
    @ControllerLog(action = "新增Test", message = "新增Test失败")
    @SaCheckPermission("test:add")
    public CommonResponse insertTest(@Validated(InsertGroup.class) @RequestBody Test test) {
        return CommonResponse.success(testService.insertTest(test), "新增成功");
    }

    @ApiOperation(value = "修改")
    @PutMapping()
    @ControllerLog(action = "修改Test", message = "修改Test失败")
    @SaCheckPermission("test:update")
    public CommonResponse updateTest(@Validated(UpdateGroup.class) @RequestBody Test test) {
        return CommonResponse.success(testService.updateTest(test), "修改成功");
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "Testid", paramType = "path", dataType = "Integer", required = true)
    @DeleteMapping("/{id}")
    @ControllerLog(action = "删除Test", message = "删除Test失败")
    @SaCheckPermission("test:delete")
    public CommonResponse deleteTest(@PathVariable("id") Integer id) {
        return CommonResponse.success(testService.deleteTest(id), "删除成功");
    }

    @ApiOperation(value = "批量删除")
    @ApiImplicitParam(name = "ids", value = "Testid逗号分割字符", paramType = "query", dataType = "String", required = true)
    @DeleteMapping("")
    @ControllerLog(action = "批量删除Test", message = "批量删除Test失败")
    @SaCheckPermission("test:batch:delete")
    public CommonResponse deleteTests(@RequestParam("ids") String ids) {
        return CommonResponse.success(testService.deleteTests(ids), "批量删除成功");
    }

    @ApiOperation(value = "查询")
    @ApiImplicitParam(name = "id", value = "Testid", paramType = "path", dataType = "Integer", required = true)
    @GetMapping("/{id}")
    @ControllerLog(action = "查询Test", message = "查询Test失败")
    @SaCheckPermission("test:get")
    public CommonResponse getTest(@PathVariable("id") Integer id) {
        return CommonResponse.success(testService.getTest(id), "查询成功");
    }

    @ApiOperation(value = "查询列表")
    @GetMapping("/list")
    @ControllerLog(action = "查询Test列表", message = "查询Test列表失败")
    @SaCheckPermission("test:list")
    public CommonResponse listTests(CommonRequest commonRequest, Test test) {
        return CommonResponse.success(testService.listTests(commonRequest, test), "查询成功");
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/pages")
    @ControllerLog(action = "分页查询Test", message = "分页查询Test失败")
    @SaCheckPermission("test:page")
    public CommonResponse listPageTests(CommonRequest commonRequest, Test test) {
        return CommonResponse.success(testService.listPageTests(commonRequest, test), "查询成功");
    }
}
